<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('半全场胜平负')" />
	<style>
      .table{
          display:table; 
          table-layout: fixed; 
      }
	</style>
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="post-form">
					<div class="select-list">
						<ul>
							<li>
								投注金额：<input type="text"  value="10000" id="tzje"/>
							</li>
							<li>
								竞彩返点：<input type="text" value="0.095"  id="jcfd"/>
							</li>
							<li>
								HG返点：<input type="text" value="0.023"  id="hgfd"/>
							</li>
							<li>
								收益率大于：<input type="text"  id="syl"/>%
							</li>
							<li>
								竞彩返还率大于：<input type="text"  id="fhl"/>%
							</li>
							<li>
								收益大于：<input type="text" id="sy"/>
							</li>
							<li>
								利润达标提醒设置：<input type="text" value="300" id="lrdb"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-cog"></i>&nbsp;设置</a>
							    <a class="btn btn-warning btn-rounded btn-sm" id="resetTime"><i class="fa fa-clock-o"></i>&nbsp;设置刷新时间</a>
								<span style="color: red;" id="timeText">10s</span><span>秒刷新</span>
								<input type="hidden" value="10" id="time"/>
							</li>
						</ul>
					</div>
				</form>
			</div>
	        
	        <div class="col-sm-12 select-table table-striped" id="continer">
	        	
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		function cellStylesales(value, row, index) {
			return {css:{background:'#FF9933'}};
		};
		var options1 = {
				showRefresh: false,
	            showColumns: false,
				showToggle: false,
				showSearch: false,
		        columns: [
					{
						field: 'Type',
						title: '类型',
						width: "240px",
						align:'center',
					},
					{
						field: 'WholeHalfLotteryWater1',
						title: '第一竞猜</br>水位',
						width: "80px",
						align:'center',
						cellStyle:cellStylesales,
						formatter: function(value, row, index) {
			                return '<span style="color:blue;">'+value+'</span>';
			            }
					},
					{
						field: 'WholeHalfLotteryWater2',
						title: '第二竞猜</br>水位',
						width: "80px",
						align:'center',
						cellStyle:cellStylesales,
						formatter: function(value, row, index) {
			                return '<span style="color:blue;">'+value+'</span>';
			            }
					},
					{
						field: 'WholeHalfLotteryWater3',
						title: '第三竞猜</br>水位',
						width: "80px",
						align:'center',
						cellStyle:cellStylesales,
						formatter: function(value, row, index) {
			                return '<span style="color:blue;">'+value+'</span>';
			            }
					},
					{
						field: 'WholeHalfPeriphery1',
						title: '第一外围</br>水位',
						width: "80px",
						align:'center',
						cellStyle:cellStylesales,
						formatter: function(value, row, index) {
			                return '<span style="color:blue;">'+value+'</span>';
			            }
					},
					{
						field: 'WholeHalfPeriphery2',
						title: '第二外围</br>水位',
						width: "80px",
						align:'center',
						cellStyle:cellStylesales,
						formatter: function(value, row, index) {
			                return '<span style="color:blue;">'+value+'</span>';
			            }
					},
					{
						field: 'BetMoneyLotteryWater1',
						title: '第一竞猜</br>下注额',
						width: "80px",
						align:'center',
						formatter: function(value, row, index) {
			                return '<span style="color:#993300;">'+value+'</span>';
			            }
					},
					{
						field: 'BetMoneyLotteryWater1',
						title: '第一竞猜</br>下注额',
						width: "80px",
						align:'center',
						formatter: function(value, row, index) {
			                return '<span style="color:#993300;">'+value+'</span>';
			            }
					},
					{
						field: 'BetMoneyLotteryWater2',
						title: '第二竞猜</br>下注额',
						width: "80px",
						align:'center',
						formatter: function(value, row, index) {
			                return '<span style="color:#993300;">'+value+'</span>';
			            }
					},
					{
						field: 'BetMoneyLotteryWater3',
						title: '第三竞猜</br>下注额',
						width: "80px",
						align:'center',
						formatter: function(value, row, index) {
			                return '<span style="color:#993300;">'+value+'</span>';
			            }
					},
					{
						field: 'BetMoneyPeriphery1',
						title: '第一外围</br>下注额',
						width: "80px",
						align:'center',
						formatter: function(value, row, index) {
			                return '<span style="color:#993300;">'+value+'</span>';
			            }
					},
					{
						field: 'BetMoneyPeriphery2',
						title: '第二外围</br>下注额',
						width: "80px",
						align:'center',
						formatter: function(value, row, index) {
			                return '<span style="color:#993300;">'+value+'</span>';
			            }
					},
					{
						filed: 'Profit',
						title: '利润',
						align:'center',
						width: "90px",
						formatter: function(value, row, index) {
							var jcReturn = $('#jcfd').val();
							var profit = (row.Profit1 + row.BetMoneyJingCai * jcReturn).toFixed(2);
							if(profit>0) return '<span style="color:red;">'+profit+'</span>';
			                return '<span style="color:#00CC00;">'+profit+'</span>';
			            }
					}
			    ]
		};
		var options2 = {
				showRefresh: false,
	            showColumns: false,
				showToggle: false,
				showSearch: false,
		        columns: []
		};
		var times = $('#time').val();
		if(localStorage.getItem("time")) {
			times = localStorage.getItem("time");
			$('#time').val(times);
		}
        var setTimes = function() {
        	setInterval((function() {
        		times =  times-1;
        		if(times < 0) {
        			times = $('#time').val();
        			getData(true)
        		}
                $('#timeText').text(times+"s");
            }), 1e3)
		};
		var renderTable = function(result) {
			if(!result || result<1) return;
			var dateDiff = function(t) {
                var e = new Date
                  , r = new Date(t)
                  , i = (r - e) / 1e3
                  , a = parseInt(i / 86400)
                  , n = parseInt(i / 3600) - 24 * a
                  , o = parseInt(i % 3600 / 60)
                  , l = parseFloat((o / 60).toFixed(1));
                return 24 * a + n + l + "小时后开赛"
            };
			function renderItem(item,index) {
				var html = [];
				html.push('<div class="row">')
				html.push('<h4 class="col-sm-12 form-header h4">'+index+'.【'+item.SerialNumber+'】'+dateDiff(item.StartTime)+'('+item.StartTime+')'+item.LeagueName + ' => ' + item.HomeField + 'Vs '+ item.OpponentField+'</h4>');
				html.push('<div class="col-sm-12">');
				html.push('	<table id="bootstrap-table1" class="table"></table>');
				html.push('</div>');
				html.push('</div>');
				var html = $(html.join('\r\n'));
				return html;
			}
			var continer = $('#continer');
			continer.empty();
			for(var i=0; i<result.length; i++) {
				var div = renderItem(result[i], i+1);
				var table1 = div.find('#bootstrap-table1');
				continer.append(div);
				options1.data = result[i].EventHedgeProfitsWholeHalf;
				table1.bootstrapTable(options1);
			}
			console.log(result);
		};
        var getData = function(isReset) {
			var baseUrl = "http://83t95.xyz:8090/api/WholeHalf?t="+(new Date).getTime();
			$.operate.get(baseUrl, renderTable, true, isReset);
        };		
        
		$(function() {
			getData();
			setTimes();
			$('#resetTime').on('click', function(){
				layer.prompt({title: '输入刷新时间单位(秒)', formType: 0}, function(pass, index){
					if(!pass || pass=='') return $.modal.msgWarning("请填写刷新时间");
					if(parseFloat(pass).toString() == "NaN") return $.modal.msgWarning("请填写正整数");
					$('#time').val(pass);
					localStorage.setItem("time",pass);
					layer.close(index);
				});
			});
		});
	</script>
</body>
</html>